package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivitiesDto;
import com.qk.entity.Activities;
import com.qk.service.ActivitiesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class ActivitiesController {
    @Autowired
    private ActivitiesService activitiesService;

    /**
     * 获取列表信息
     */
    @GetMapping("/activities")
    public Result list(ActivitiesDto activitiesDto){
        log.info("查询活动:  channel: {}, type: {}, status: {}, page: {}, pageSize: {}",  activitiesDto.getChannel(), activitiesDto.getType(), activitiesDto.getStatus(), activitiesDto.getPage(), activitiesDto.getPageSize());
        PageResult<Activities> pageResult =activitiesService.list(activitiesDto);
        return Result.success(pageResult);
    }

    /**
     * 删除活动
     */
    @DeleteMapping("/activities/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除活动: {}", id);
        activitiesService.delete(id);
        return Result.success();
    }

    /**
     * 添加 活动
     */
    @PostMapping("/activities")
    public Result add(@RequestBody Activities activities){
        log.info("添加活动: {}", activities);
        activitiesService.add(activities);
        return Result.success();
    }

    /**
     * 根据Id查询
     */
    @GetMapping("/activities/{id}")
    public Result getById(@PathVariable Integer id){
        Activities activities =activitiesService.getById(id);
        return Result.success(activities);
    }
    /**
     * 修改活动
     */
    @PutMapping("/activities")
    public Result update(@RequestBody Activities activities){
        log.info("修改活动: {}",activities);
        activitiesService.update(activities);
        return Result.success();
    }

    /**
     * 查询指定类型的活动
     */
    @GetMapping("/activities/type/{type}")
    public Result getByType(@PathVariable Integer type){
        List<Activities> activitiesList =activitiesService.getByType(type);
        return Result.success(activitiesList);
    }
}
